﻿app.controller('PayResultCtrl', ['$scope', '$http', 'httpPlus', '$stateParams','$state', function ($scope, $http, httpPlus, $stateParams,$state) {
    $scope.GUID = $stateParams.id;
    $scope.eventDetail = {};
    $scope.card = {
        list:[],
        currCard:undefined
    };
    $scope.payType = {
        list:  [{
            name: '微信支付',
            type: 'wechatpay',
            rest: undefined,
            points: undefined
        }],
        currPayType:undefined,
        changePayType_change:function(){
            console.log($scope.payType.currPayType);
        }
    };
    if ($stateParams.id == undefined) {
        return $scope.eventDetail.PayStatus = undefined;
    };
    function initData(){
      return  httpPlus
            .MMB2RRRApi('MyMemberEventRegistration/GetMyEventByGUID', {
                _guid: $stateParams.id
            })
            .then(function (data) {
                $scope.eventDetail = data.MyEvent;
            })
    };
    $scope.payBill_click = function () {
        if($scope.payType.currPayType == 'wechatpay'){
            window.location.replace('../../QuickPay/PayByEventRegisteration.aspx?eventGUID=' + $scope.eventDetail.GUID);
        }else{
            httpPlus
                .MMB2RRRApi('MyMemberEventRegistration/MyMemberCard_Consume',{
                    _cardCode:$scope.card.currCard.CardCode,
                    _money:$scope.eventDetail.TotalFee/100,
                    _remark:'',
                    _guid: $stateParams.id,
                    _user:$scope.eventDetail.Contact_Name
                })
                .then(function(){
                    initData();
                })
                .catch(function(err){
                    alert(JSON.stringify(err.ResultMsg));
                })
        }
    };
    //返回
    $scope.return_click = function(){
        //$state.go('wx.activityEnter',{'id': $stateParams.id})
    };
    initData()
        .then(function () {
            return  httpPlus
                .MMB2RRRApi('MyMemberEventRegistration/GetMyMemberCard_ByOid')
        })
        .then(function(data){
            console.log(data);
            $scope.card.list = data;
            $scope.card.currCard = data[0];
            if($scope.card.currCard !=undefined && $scope.payType.list.length == 1){
                $scope.payType.list.push({
                    name:'会员卡',
                    type:'cardpay',
                    rest:$scope.card.currCard.AvailableValue,
                    points:$scope.card.currCard.AvailablePoint
                });
            };
            $scope.payType.currPayType = $scope.payType.list[0].type;
        })
}]);
